home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 4 / BBS in a Box - Macintosh - Volume IV (January 1992) (BBS in a Box).iso / Files / Util / In-Iz / InitMount.cpt / InitMount Folder / Init Mounter.c next >
Encoding:
C/C++ Source or Header  |  1990-06-21  |  2.6 KB  |  79 lines  |  [TEXT/KAHL]

  1. /* Init Mounter.c                                                        */
  2. /*    Version 1.0a0                                                        */
  3. /*                                                                        */
  4. /*     This program is intended to allow the user to execute INITs after    */
  5. /*    the startup process has been completed.                                */
  6. /*                                                                        */
  7. /*    Notes:                                                                */
  8. /*        Currently this only works under the Finder and not Multi-Finder    */
  9. /*            -I have not had time to figure out why this is.                */
  10. /*                                                                        */
  11. /*        Does not work with ALL INITs.  So far those that don't are:        */
  12. /*            zhierDA                                                        */
  13. /*            Shield Init                                                    */
  14. /*            & probably others                                            */
  15. /*                                                                        */
  16. /*    This code is in the public domain except where it infringes on        */
  17. /*    any copyrights and then it is not.                                    */
  18. /*                                                                        */
  19. /*    Chris Faigle                                                        */
  20. /*    AppleLink: CHRIS.FAIGLE                                                */
  21.  
  22.  
  23. main()
  24. {
  25.     int            init_file_ref_num;
  26.     int            ret;
  27.     SFReply        reply_rec;
  28.     Point        where={100,100};
  29.     SFTypeList    my_list;
  30.     Handle        init_to_execute;
  31.     long        code;
  32.     long        hold;
  33.  
  34.     InitGraf(&thePort);
  35.     InitFonts();
  36.     FlushEvents( everyEvent, 0 );
  37.     InitWindows();
  38.     InitMenus();
  39.     TEInit();
  40.     InitDialogs(0L);
  41.     InitCursor();
  42.  
  43.     my_list[0]='INIT';    /* Inits are in INIT types        */
  44.     my_list[1]='cdev';    /* and cdev types                */
  45.     my_list[2]='xNIT';    /* This is for initCDEV users!    */
  46.     my_list[3]='xdev';    /* This is for initCDEV users!    */
  47.     InitPack(3);
  48.     SFGetFile(where,"\p",0l,4,&my_list,0l,&reply_rec);    /* Get file                    */
  49.     if(!reply_rec.good)                                    /* Did user cancel            */
  50.     {
  51.         ExitToShell();                                    /* Yes-exit                    */
  52.     }
  53.     if((init_file_ref_num=OpenResFile(reply_rec.fName))==-1)    /* Did open fail?    */
  54.     {
  55.         ExitToShell();                                            /* Yes - exit        */
  56.     }
  57.     init_to_execute=GetIndResource('INIT',1);    /* Get the first Init resource        */
  58.     if(init_to_execute==0l)                        /* Get one?                            */
  59.     {
  60.         ExitToShell();                            /* No - exit                        */
  61.     }
  62.     DetachResource(init_to_execute);            /* Detatch the code                    */
  63.     HLock(init_to_execute);                        /* and lock it                        */
  64.     code=(long)*init_to_execute;        /* Get the address of the Init to execute    */
  65.     asm                                    /* Our sneaky little assembler routine        */
  66.     {
  67.         movem.l    d0-d7/a0-a6,-(a7)        /* Save registers                            */
  68.         move.l    SysZone,a0                /* Move the System zone to A0                */
  69.         _SetZone                        /* Make the zone the system zone            */
  70.         move.l    code,a1                    /* Move contents of code to a1                */
  71.         jsr        (a1)                    /* JSR to the start of the init code        */
  72.         move.l    ApplZone,a0                /* Move the ApplZone to A0                    */
  73.         _SetZone                        /* Set the zone to the ApplZone                */
  74.         movem.l (a7)+,d0-d7/a0-a6        /* Restore all registers                    */
  75.     }
  76.     CloseResFile(init_file_ref_num);    /* Close the resource file                    */
  77. }
  78.  
  79.